//
//  Task_GetFocusImage.m
//  iphone.mobileoa
//
//  Created by 李林 on 13-10-23.
//  Copyright (c) 2013年 Epoint. All rights reserved.
//

#import "Task_GetInfoHeadPic.h"

@implementation Task_GetInfoHeadPic
-(void)execute
{

    NSString *url = NSLocalizedString(@"Epoint_DNet_WMH", @"");
    NSString *ValidateData = [EpointBizTools getToken];
    NSString *namespace = NSLocalizedString(@"Epoint_DNet_WMH_NameSpace", @"");
    
    
    int screenHeight = [[UIScreen mainScreen]bounds].size.height;
    
    
    //    4s(640*432)
    //    5(640*590)
    NSString *width = @"640";
    NSString *height = @"432";
    if(screenHeight>=568){
        height = @"600";
    }
    
    InfoListModel *hnm = [params objectForKey:@"HeadNewsModel"];
    
    NSString *method = @"GetInfoHeadPic";
    NSString *ParasXml = @"<![CDATA[<?xml version=\"1.0\" encoding=\"gb2312\"?><paras><HeadNewsAttachGuid>%@</HeadNewsAttachGuid></paras>]]>";
    ParasXml = [NSString stringWithFormat:ParasXml,hnm.HeadNewsAttachGuid];
    
    EpointWebServiceUtil *ws = [[EpointWebServiceUtil alloc]initWithUrl:url namespace:namespace method:method];
    [ws addParameterForString:@"ValidateData" value:ValidateData];
    [ws addParameterForString:@"ParasXml" value:ParasXml];
    NSString *bs =  ws.start;

    
    NSString *status = [EpointStringUtil getXMLFormatedAttribute:bs :@"Status"];
    
    NSMutableArray *bd = [[NSMutableArray alloc]init];
    [bd addObject:hnm];
    if ([status isEqualToString:@"True"]) {
        [bd addObject:@"1"];
        [bd addObject:[Task_GetInfoHeadPic JieXiXML:bs]];
    }
    else
    {
        [bd addObject:@"0"];
        [bd addObject:@"falure"];
    }
    [self sendDataRefreshUI:bd];
}

#pragma mark 解析XML
+(HeadPicModel *)JieXiXML:(NSString *)bs
{

    NSString *UserArea = [EpointStringUtil getXMLFormatedAttributeBsWithTag:bs xmlTag:@"UserArea"];
    //解析
    GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithXMLString:UserArea  options:0 error:nil];
    GDataXMLElement *rootElement = [doc rootElement];
    NSArray *arrays = [rootElement elementsForName:@"SingleFile"];
    
    NSMutableArray *dataList = [[NSMutableArray alloc]init];
    
    for (GDataXMLElement *arr in arrays) {
        HeadPicModel *fileInfo = [[HeadPicModel alloc]init];
        
        GDataXMLElement *AttID = [[arr elementsForName:@"AttID"] objectAtIndex:0];
        fileInfo.AttID = [AttID stringValue];
        
        GDataXMLElement *AttFileName = [[arr elementsForName:@"AttFileName"] objectAtIndex:0];
        fileInfo.AttFileName = [AttFileName stringValue];
        
        GDataXMLElement *AttContent = [[arr elementsForName:@"AttContent"] objectAtIndex:0];
        fileInfo.AttContent = [AttContent stringValue];
        
        fileInfo.fileData = [GTMBase64 decodeString:fileInfo.AttContent];
        
        NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
        [ud setObject:fileInfo.fileData forKey:fileInfo.AttID];
        
        [dataList addObject:fileInfo];
    }
    return [dataList objectAtIndex:0];
}


@end
